#include "functions.h"
#include<string.h>

int main()
{
  int m = 28;
  int n = 12;
  double* y = new double[m]();
  double _y[m] = {25.9, 29.5, 27.9, 25.9, 29.9, 29.9, 30.9,
		  28.9, 84.9, 82.9, 35.9, 31.5, 31.0, 30.9,
		  30.0, 28.9, 36.9, 41.9, 40.5, 43.9, 37.5,
		  37.9, 44.5, 37.9, 38.9, 36.9, 45.8, 41.0};
  memcpy(y, _y, sizeof(_y));
  double** A = new double*[m];
  for(int i = 0; i < m; i++)
    A[i] = new double[n]();
  A[0][1] = 4.9176;
  A[1][1] = 5.0208;
  A[2][1] = 4.5429;
  A[3][1] = 4.5573;
  A[4][1] = 5.0597;
  A[5][1] = 3.8910;
  A[6][1] = 5.8980;
  A[7][1] = 5.6039;
  A[8][1] = 15.4202;
  A[9][1] = 14.4598;
  A[10][1] = 5.8282;
  A[11][1] = 5.3003;
  A[12][1] = 6.2712;
  A[13][1] = 5.9592;
  A[14][1] = 5.0500;
  A[15][1] = 5.6039;
  A[16][1] = 8.2426;
  A[17][1] = 6.6969;
  A[18][1] = 7.7841;
  A[19][1] = 9.0384;
  A[20][1] = 5.9894;
  A[21][1] = 7.5422;
  A[22][1] = 8.7951;
  A[23][1] = 6.0931;
  A[24][1] = 8.3607;
  A[25][1] = 8.1400;
  A[26][1] = 9.1416;
  A[27][1] = 12.0000;
  for(int i = 0; i < m; i++)
    {
      A[i][0] = A[i][2] = A[i][5] = A[i][9] = A[i][10] = 1.0;
      A[i][6] = 6.0;
      A[i][7] = 3.0;
      A[i][11] = 0.0;
    }
  A[8][2] = A[9][2] = 2.5;
  A[16][2] = A[17][2] = A[18][2] = A[21][2] = A[22][2]
    = A[23][2] = A[24][2] = A[26][2] = A[27][2] = 1.5;
  A[0][3] = 3.4720;
  A[1][3] = 3.5310;
  A[2][3] = 2.2750;
  A[3][3] = 4.0500;
  A[4][3] = 4.4550;
  A[5][3] = 4.4550;
  A[6][3] = 5.8500;
  A[7][3] = 9.5200;
  A[8][3] = 9.800;
  A[9][3] = 12.8;
  A[10][3] = 6.435;
  A[11][3] = 4.9883;
  A[12][3] = 5.52;
  A[13][3] = 6.666;
  A[14][3] = 5.0;
  A[15][3] = 9.52;
  A[16][3] = 5.15;
  A[17][3] = 6.092;
  A[18][3] = 7.102;
  A[19][3] = 7.8;
  A[20][3] = 5.52;
  A[21][3] = 4.0;
  A[22][3] = 9.89;
  A[23][3] = 6.7265;
  A[24][3] = 9.15;
  A[25][3] = 8.0;
  A[26][3] = 7.3262;
  A[27][3] = 5.0;
  A[0][4] = 0.998;
  A[1][4] = 1.5;
  A[2][4] = 1.175;
  A[3][4] = 1.232;
  A[4][4] = 1.121;
  A[5][4] = 0.988;
  A[6][4] = 1.24;
  A[7][4] = 1.501;
  A[8][4] = 3.42;
  A[9][4] = 3.0;
  A[10][4] = 1.225;
  A[11][4] = 1.552;
  A[12][4] = 0.975;
  A[13][4] = 1.121;
  A[14][4] = 1.02;
  A[15][4] = 1.501;
  A[16][4] = 1.664;
  A[17][4] = 1.488;
  A[18][4] = 1.376;
  A[19][4] = 1.5;
  A[20][4] = 1.256;
  A[21][4] = 1.69;
  A[22][4] = 1.82;
  A[23][4] = 1.652;
  A[24][4] = 1.777;
  A[25][4] = 1.504;
  A[26][4] = 1.831;
  A[27][4] = 1.200;
  A[1][5] = A[8][5] = A[9][5] = A[10][5] = A[13][5]
    = A[16][5] = A[20][5] = A[22][5] = A[24][5] = A[25][5] = A[27][5] = 2.0;
  A[7][5] = A[14][5] = A[15][5] = 0.0;
  A[17][5] = A[19][5] = A[26][5] = 1.5;
  A[0][6] = A[1][6] = A[6][6] = A[17][6] = A[19][6] = A[25][6] = 7.0;
  A[8][6] = 10.0;
  A[9][6] = 9.0;
  A[12][6] =A[14][6] = 5.0;
  A[16][6] = A[22][6] = A[24][6] = A[26][6] = 8.0;
  A[0][7] = A[1][7] = A[16][7] = A[22][7] = A[24][7] = A[26][7] = 4.0;
  A[8][7] = A[9][7] = 5.0;
  A[12][7] = A[14][7] = 2.0;
  A[0][8] = 42.0;
  A[1][8] = 62.0;
  A[2][8] = 40.0;
  A[3][8] = 54.0;
  A[4][8] = 42.0;
  A[5][8] = 56.0;
  A[6][8] = 51.0;
  A[7][8] = 32.0;
  A[8][8] = 42.0;
  A[9][8] = 14.0;
  A[10][8] = 32.0;
  A[11][8] = 30.0;
  A[12][8] = 30.0;
  A[13][8] = 32.0;
  A[14][8] = 46.0;
  A[15][8] = 32.0;
  A[16][8] = 50.0;
  A[17][8] = 22.0;
  A[18][8] = 17.0;
  A[19][8] = 23.0;
  A[20][8] = 40.0;
  A[21][8] = 22.0;
  A[22][8] = 50.0;
  A[23][8] = 44.0;
  A[24][8] = 48.0;
  A[25][8] = 3.0;
  A[26][8] = 31.0;
  A[27][8] = 30.0;
  A[2][9] = A[5][9] = A[6][9] = A[8][9] = A[13][9] = A[18][9] = 2.0;
  A[0][9] = A[4][9] = A[19][9] = A[27][9] = 3.0;
  A[3][9] = A[9][9] = A[14][9] = A[16][9]
    = A[20][9] = A[23][9] = A[26][9] = 4.0;
  A[11][10] = A[12][10] = 2.0;
  A[19][10] = A[25][10] = 3.0;
  A[6][11] = A[8][11] = A[9][11] = A[14][11]
    = A[17][11] = A[20][11] = A[22][11] = A[24][11] = A[27][11] = 1.0;
  LS_QR_Householder(A, y, m, n);
  for(int i = 0; i < n; i++)
    std::cout << "x[" << i << "] = " << y[i] << std::endl;
  for(int i = 0; i < m; i++)
    delete [] A[i];
  delete [] A;
  delete [] y;
  return 0;
};
